/**********************************************************************
 * SailmiPIM - modular cross-platform feature rich internet client.
 * Copyright (C) 2006-2014  Georg Rudoy
 *
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
 **********************************************************************/

#include "eventlog.h"
#include <QIcon>
#include <util/core/util.h>
#include <sailmipim/core/icoreproxy.h>
#include <sailmipim/core/iiconthememanager.h>
#include "core.h"
#include "eventlogwidget.h"

namespace SailmiPIM
{
namespace Plugin::EventLog
{
    void EventLog::Init (ICoreProxy_ptr proxy)
	{
        EventLogWidget::SetParentMultiTabs (this);

        Util::InstallTranslator ("sailmipim_eventlog");

		Core::Instance ().SetProxy (proxy);

		TabClassInfo tabClass =
		{
            "EventLog",
            tr ("EventLog"),
			GetInfo (),
			GetIcon (),
			50,
			TFOpenableByRequest | TFByDefault | TFSuggestOpening
		};
		TabClasses_ << tabClass;
	}

    void EventLog::SecondInit ()
	{
		Core::Instance ().SecondInit ();
	}

    void EventLog::Release ()
	{
		Core::Instance ().Release ();
	}

    QByteArray EventLog::GetUniqueID () const
	{
        return "com.sailmi.pim.plugin.EventLog";
	}

    QString EventLog::GetName () const
	{
        return "EventLog";
	}

    QString EventLog::GetInfo () const
	{
		return tr ("Eventlog of downloads and recent events");
	}

    QIcon EventLog::GetIcon () const
	{
		return GetProxyHolder ()->GetIconThemeManager ()->GetPluginIcon ();
	}

    bool EventLog::IsCore() const
    {
        return false;
    }

    TabClasses_t EventLog::GetTabClasses () const
	{
		return TabClasses_;
	}

    void EventLog::TabOpenRequested (const QByteArray& tabClass,const QMap<QString,QString>& args)
	{
        if (tabClass == "EventLog")
			Core::Instance ().handleNewTabRequested ();
		else
			qWarning () << Q_FUNC_INFO
					<< "unknown tab class"
					<< tabClass;
	}

    QModelIndex EventLog::MapToSource (const QModelIndex& index) const
	{
		return Core::Instance ().MapToSourceRecursively (index);
	}

    void EventLog::RecoverTabs (const QList<TabRecoverInfo>& infos)
	{
		Core::Instance ().RecoverTabs (infos);
	}

    bool EventLog::HasSimilarTab (const QByteArray&, const QList<QByteArray>&) const
	{
		return true;
	}
}
}

SAILMIPIM_EXPORT_PLUGIN (sailmipim_eventlog, SailmiPIM::Plugin::EventLog::EventLog);
